package org.jeecg.common.util;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author liguang
 * @version 1.0.0
 * @Project jeecg-boot
 * @Package org.jeecg.common.util
 * @ClassName ListCopyUtils.java
 * @createTime 2021年11月24日 12:02:00
 * @Description 深度拷贝list
 */
public class ListCopyUtils<T> {
        public void copyList(Object obj, List<T> list2, Class<T> classObj) {
            if ((!Objects.isNull(obj)) && (!Objects.isNull(list2))) {
                List list1 = (List) obj;
                list1.forEach(item -> {
                    try {
                        T data = classObj.newInstance();
                        BeanUtils.copyProperties(item, data);
                        list2.add(data);
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                });
            }
        }
}
